今天把主要流程順過一遍,剩下的就只是把程式惡補出來了,明後兩天員工旅遊,不多準備點文章,怕要是開空窗了就不好了!
主要就是按照流程圖,把相關流程先定義好,等著幾個小程序測試OK就可以貼上了。
FUNCTION MAIN (V_TMP IN VARCHAR2 ) RETURN VARCHAR2 IS
PRAGMA AUTONOMOUS_TRANSACTION;
v_msg varchar2(2000); -- add by yafuu 2013/10/12
BEGIN
IF UPPER(V_TMP) = 'NEW' THEN --重頭玩過
INIT_GUESS; --初始化設定
V_MSG := GET_NEXT_GUESS; --Get Next Guess
IF V_MSG = 'OK' THEN --1 st=1234,2 nd = 5678,此版本不改邏輯
V_MSG := SHOW_GUESS; --Show the Guess....and wait....
ELSE
NULL; --不會發生
END IF;
--
ELSIF UPPER(V_TMP) = 'EXIT' THEN --離開
INIT_GUESS; --初始化設定
V_MSG := 'Bye!';
ELSIF V_TMP IN ('00','01','02','03','04','10','11','12','13','20','21','22','30','40') THEN --檢核猜測結果
--
update_result(v_tmp); --將結果更新到最後一次的猜測,供後續檢測用
--
IF V_TMP = '40' THEN --Bingo
INIT_GUESS; --初始化設定
V_MSG := 'Bingo!'||CHR(13)||CHR(10)|| SHOW_HISTORY;
ELSE --Not yet finish, keep guess
V_MSG := GET_NEXT_GUESS; --Get Next Guess
IF V_MSG = 'OK' THEN --確實可找到下一組的情況下
V_MSG := SHOW_GUESS; --Show the Guess....and wait....
ELSE --NG
V_MSG := '推算不出結果,請確認!'||CHR(13)||CHR(10)|| SHOW_HISTORY;
END IF;
--V_MSG := '加油!男孩!.....'; --老大參與加油!男孩!的國片演出駱駝一角,為守護糖廠盡一份力!
END IF;
ELSE ---當亂輸一通發生時。
V_MSG := SHOW_HISTORY;
end if;
return v_msg;
END;
其他小程序
FUNCTION SHOW_HISTORY return varchar2 IS --Add By yafuu 2013/10/10
CURSOR C1 IS
select seq_id, gs01, gs02, gs03, gs04, gs0a, gs0b
FROM YAFUU_GUESS_HISTORY
ORDER BY SEQ_ID;
v_history varchar2(2000);
BEGIN
v_history := '目前電腦猜測的紀錄如下:'||chr(13)||chr(10);
for i in c1 loop
V_HISTORY := V_HISTORY||I.SEQ_ID||'. '||I.GS01||I.GS02||I.GS03||I.GS04||' 結果: '||
i.gs0a||'A '||i.gs0b||'B'||chr(13)||chr(10);
END LOOP;
v_history := v_history||'===== End ======'||chr(13)||chr(10);
--以上如果需要有玩過才顯示,自行增加條件
--
V_HISTORY := V_HISTORY||''||CHR(13)||CHR(10);
V_HISTORY := V_HISTORY||'Help.....'||CHR(13)||CHR(10);
V_HISTORY := V_HISTORY||'NEW = 重玩,每次重新玩都必須執行這個參數.'||CHR(13)||CHR(10);
V_HISTORY := V_HISTORY||'EXIT = 離開.'||CHR(13)||CHR(10);
--
return v_history; --未來是Function
--dbms_output.put_line(v_history);
END;
--
FUNCTION GET_NEXT_GUESS RETURN VARCHAR2 IS --Add By yafuu 2013/10/11
V_MSG VARCHAR2(2000); -- add by yafuu 2013/10/12
V_CNT NUMBER;
BEGIN
--
--
SELECT nvl(max(seq_id), 0) seq_id
INTO V_CNT
FROM YAFUU_GUESS_HISTORY;
IF V_CNT = 0 THEN
INSERT INTO YAFUU_GUESS_HISTORY (SEQ_ID, GS01, GS02, GS03, GS04, GS0A, GS0B, GS_MATCH, REMARK)
VALUES (1, 1, 2, 3, 4, NULL, NULL, NULL, NULL);
V_MSG := 'OK';
ELSIF V_CNT = 1 THEN
INSERT INTO YAFUU_GUESS_HISTORY (SEQ_ID, GS01, GS02, GS03, GS04, GS0A, GS0B, GS_MATCH, REMARK)
VALUES (2, 5, 6, 7, 8, NULL, NULL, NULL, NULL);
V_MSG := 'OK';
ELSE
NULL; --主演算部分..@@@
--
INSERT INTO YAFUU_GUESS_HISTORY (SEQ_ID, GS01, GS02, GS03, GS04, GS0A, GS0B, GS_MATCH, REMARK)
VALUES (V_CNT + 1, 0, 0, 0, 0, 0, 1, NULL, NULL);
--check [OK] or [NG]
V_MSG := 'OK';
END IF;
--
commit;
RETURN V_MSG;
END;
--
FUNCTION SHOW_GUESS RETURN VARCHAR2 IS --Add By yafuu 2013/10/11
V_MSG VARCHAR2(2000); -- add by yafuu 2013/10/12
cursor c1 is
SELECT SEQ_ID, GS01, GS02, GS03, GS04
FROM YAFUU_GUESS_HISTORY A
ORDER BY SEQ_ID desc;
BEGIN
FOR I IN C1 LOOP
--
V_MSG := '第'||I.seq_id||'次我猜: '||I.GS01||I.GS02||I.GS03||I.GS04||' 請告訴我結果是?A?B,ex, 01 = 0A1B.';
exit;
end loop;
RETURN V_MSG;
END;
Package 頭
create or replace
PACKAGE YAFUU168 AS
FUNCTION MAIN (V_TMP IN VARCHAR2 ) return varchar2;
PROCEDURE INIT_GUESS;
FUNCTION SHOW_HISTORY RETURN VARCHAR2; --Add By yafuu 2013/10/10
FUNCTION GET_NEXT_GUESS RETURN VARCHAR2; --Add By yafuu 2013/10/11
FUNCTION SHOW_GUESS RETURN VARCHAR2; --Add By yafuu 2013/10/11
PROCEDURE update_result(v_tmp varchar2);
END yafuu168;
周末愉快!